use std::str::Utf8Error;

#[derive(Debug, thiserror::Error)]
pub enum HttpReceiveError {
    #[error("Parse http error: {0}")]
    Parse(#[from] HttpParseError),

    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),
}

#[derive(Debug, thiserror::Error)]
pub enum HttpSendError {
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),
}

#[derive(Debug, thiserror::Error)]
pub enum HttpParseError {
    #[error("Header contains invalid characters. Key: {0}")]
    InvalidUtf8String(Utf8Error),

    #[error("Unsupport content type: {0}")]
    UnsupportedContentType(String),
    #[error("Unsupported HTTP Method: {0}")]
    UnsupportedHttpMethod(&'static str),
    #[error("Unsupported HTTP Version: {0}")]
    UnsupportedHttpVersion(&'static str),

    #[error("Invalid body: {0}")]
    InvalidBodyFormat(String),
    #[error("Invalid uri: {0}")]
    InvalidUri(String),
    #[error("Invalid request format: {0}")]
    InvalidRequest(String),
    #[error("Invalid response format: {0}")]
    InvalidResponse(String),

}

impl From<Utf8Error> for HttpParseError {
    fn from(value: Utf8Error) -> Self {
        Self::InvalidUtf8String(value)
    }
}
